using System;
using System.Collections.Generic;
using System.Text;
using Fuzzware.Common.Encoding;
using Fuzzware.Common.DataSchema;

namespace Fuzzware.ConvertFromXML.Processors
{
    class CharLengthFn
    {
        /// <summary>
        /// Returns the number of characters in the source node
        /// </summary>
        /// <param name="SerialisedSourceNode"></param>
        /// <param name="SourceNode"></param>
        /// <param name="TargetNodeValue"></param>
        public void CharLength(ref byte[] operand, IOutputNode SourceNode, IOutputNode TargetNode)
        {
            Encoding Enc = SourceNode.OutputEncoding;
            int len = Enc.GetCharCount(operand);
            String EncValue = len.ToString();

            if (Coder.NeedsEncoding(TargetNode.TypeCode))
                EncValue = Coder.MakeEncoded(BitConverter.GetBytes(len), TargetNode.TypeCode);

            //operand = Coder.EncodeForOutput(TargetNode.OutputEncoding.GetBytes(len.ToString()), TargetNode.TypeCode, TargetNode.OutputAs, TargetNode.OutputEncoding);
            operand = TargetNode.OutputEncoding.GetBytes(EncValue);
        }
    }
}
